package com.androidplex.bucketlist;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.androidplex.bucketlist.model.BucketListItem;
import com.androidplex.bucketlist.model.BucketListing;

/**
 * A fragment representing a single Item detail screen.
 * This fragment is either contained in a {@link ItemListActivity}
 * in two-pane mode (on tablets) or a {@link ItemDetailActivity}
 * on handsets.
 */
public class ItemDetailFragment extends Fragment {
    /**
     * The fragment argument representing the item ID that this fragment
     * represents.
     */
    public static final String ARG_ITEM_ID = "item_id";

    /**
     * The content this fragment is presenting.
     */
    private BucketListItem mItem;

    View rootView;



    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public ItemDetailFragment() {
    }



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments().containsKey(ARG_ITEM_ID)) {
            // Load the dummy content specified by the fragment
            // arguments. In a real-world scenario, use a Loader
            // to load content from a content provider.
            mItem = BucketListing.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);

        if (mItem != null) {
        // Show the dummy content as text in a TextView.
            updateView();
            TextView descText = (TextView) rootView.findViewById(R.id.item_detail);
            descText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    mItem.updateDescription("EXPERIMENTAL");

                    updateView();
                }
            });
        }


        return rootView;
    }

    public void updateView() {
        if (mItem != null) {
            TextView descText = (TextView) rootView.findViewById(R.id.item_detail);
            descText.setText(mItem.getDescription());
        }
    }


}
